package Project;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

import top.college.dao.JDBC_SQL;
import top.college.dao.JDBC_ConnClose;

public class ReLoginMain {
	static Scanner sc = new Scanner(System.in);
	static JDBC_SQL sql = new JDBC_SQL();
	public static String logIdVO = null;
	static String logPwVO = null;
	static Connection conn = null;
	static PreparedStatement pstmt = null;
	static ResultSet rs = null;	
	
	public static void loginScreen() {
		System.out.println("성적 관리 시스템 입니다.");
		while ( true ) {
			System.out.print("로그인 아이디를 입력하세요 : ");
			logIdVO = sc.next();
			System.out.print("비밀번호를 입력하세요 : ");
			logPwVO = sc.next();
			try {
				conn = JDBC_ConnClose.openDataBase();
				pstmt = conn.prepareStatement( sql.LoginAdminSelect );
				pstmt.setString( 1, logIdVO );
				pstmt.setString( 2, logPwVO );
				rs = pstmt.executeQuery();
				if ( rs.next() ) {
					System.out.println( rs.getString( 1 ) + " 관리자님 로그인을 환영합니다." );
					System.out.println("관리자 업무 화면으로 이동합니다.");
					ReAdminMain.AdminScreen();
					break;
				} else {
					pstmt = conn.prepareStatement(sql.LoginProfSelect );
					pstmt.setString( 1, logIdVO );
					pstmt.setString( 2, logPwVO );
					rs = pstmt.executeQuery();
					if ( rs.next () ) {
						System.out.println( rs.getString( 1 ) + " 교수님 로그인을 환영합니다." );
						System.out.println("교수 업무 화면으로 이동합니다.");
						ReProfessorMain.ProfessorScreen();
						break;
					} else { 
						pstmt = conn.prepareStatement( sql.LoginStdSelect );
						pstmt.setString( 1, logIdVO );
						pstmt.setString( 2, logPwVO );
						rs = pstmt.executeQuery();
						if ( rs.next () ) {
							System.out.println( rs.getString( 1 ) + " 학생 로그인을 환영합니다." );
							System.out.println("학생 업무 화면으로 이동합니다.");
							ReStudentMain.StudentScreen();
							break;
						} 
					}
				}
			} catch ( Exception e ) {
				e.printStackTrace();
			} finally {
				JDBC_ConnClose.closeDataBase(conn, pstmt, rs);
			}
			System.out.println( "아이디 또는 비밀번호를 잘못입력하셨습니다. 다시 확인해주세요." );
		}
	}
}
